home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / gprim / bbox / bboxunion.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-26  |  1.7 KB  |  62 lines

  1. /* Copyright (c) 1992 The Geometry Center; University of Minnesota
  2.    1300 South Second Street;  Minneapolis, MN  55454, USA;
  3.    
  4. This file is part of geomview/OOGL. geomview/OOGL is free software;
  5. you can redistribute it and/or modify it only under the terms given in
  6. the file COPYING, which you should have received along with this file.
  7. This and other related software may be obtained via anonymous ftp from
  8. geom.umn.edu; email: software@geom.umn.edu. */
  9.  
  10. /* Authors: Charlie Gunn, Stuart Levy, Tamara Munzner, Mark Phillips */
  11.  
  12. #include "bboxP.h"
  13.  
  14. #define    BB_MIN(a,b)    ( (a) <= (b) ? a : b )
  15. #define    BB_MAX(a,b)    ( (a) >= (b) ? a : b )
  16.  
  17. BBox *
  18. BBoxUnion(BBox *bbox1, BBox *bbox2)
  19. {
  20.     return BBoxUnion3(bbox1, bbox2, NULL);
  21. }
  22.  
  23. BBox *
  24. BBoxUnion3(register BBox *bbox1, register BBox *bbox2, register BBox *result)
  25. {
  26.     HPoint3    min, max;
  27.  
  28.  
  29.     /* TAKE CARE OF THE CASE OF EITHER CUBE BEING NULL */
  30.     if (!bbox1) {
  31.         if(!bbox2) {
  32.         if(result) {
  33.             static Point Max = { -1e10,-1e10,-1e10, 1 };
  34.             static Point Min = {  1e10, 1e10, 1e10, 1 };
  35.             result->min = Min;
  36.             result->max = Max;
  37.         }
  38.         return result;
  39.         }
  40.         bbox1 = bbox2;
  41.         bbox2 = NULL;
  42.     }
  43.     min = bbox1->min;
  44.     max = bbox1->max;
  45.     if(bbox2) {
  46.         if(min.x > bbox2->min.x) min.x = bbox2->min.x;
  47.         if(max.x < bbox2->max.x) max.x = bbox2->max.x;
  48.         if(min.y > bbox2->min.y) min.y = bbox2->min.y;
  49.         if(max.y < bbox2->max.y) max.y = bbox2->max.y;
  50.         if(min.z > bbox2->min.z) min.z = bbox2->min.z;
  51.         if(max.z < bbox2->max.z) max.z = bbox2->max.z;
  52.     }
  53.     /* this needs to be fleshed out for true 4D */
  54.     min.w = max.w = 1.0;
  55.     if(result == NULL)
  56.         return (BBox *)GeomCCreate(NULL, BBoxMethods(),
  57.                 CR_MIN, &min, CR_MAX, &max, CR_END);
  58.     result->min = min;
  59.     result->max = max;
  60.     return result;
  61. }
  62.